var gulp = require('gulp'),
    rename = require('gulp-rename'),
    uglify = require("gulp-uglify"),
    clean = require('gulp-clean'),
    gutil = require('gulp-util'),
    babel = require("gulp-babel"),
    plumber = require('gulp-plumber'),
    cached = require('gulp-cached'),
    livereload = require('gulp-livereload');
    gulp.task('js',function() {
    return gulp.src('src/**/*.js')
        .pipe(cached('js'))
        .pipe(plumber())
        .pipe(babel({
            presets : ['es2015']
        }))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify().on('error', function(err){
            gutil.log(err);
            this.emit('end');
        }))
        .pipe(gulp.dest('dist'))
        .pipe(livereload())//实时刷新
});
gulp.task("clean_static", function(){
    return gulp.src(['./dist/js'])
        .pipe(clean());
});
gulp.task('watch',function(){
    livereload.listen();
    gulp.watch('src/**/*.js',['js']);
});
gulp.task('default', ['clean_static', 'watch'], function(done){
    gulp.start('js');
});
